using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PersonDataInterf;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientRepresentativeController : Controller
    {
		private readonly ISexRepository sexRepository;
		private readonly IPersonPictureRepository personpictureRepository;
		private readonly IPersonAccountRepository personaccountRepository;
		private readonly IPersonStatusRepository personstatusRepository;
		private readonly IPatientRepository patientRepository;
		private readonly IPatientRepresentativeRepository patientrepresentativeRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientRepresentativeController()// : this(new SexRepository(), new PersonPictureRepository(), new PersonAccountRepository(), new PersonStatusRepository(), new PatientRepository(), new PatientRepresentativeRepository())
        {
            this.sexRepository = Registry.RepositoryFactory.GetSexRepository();
            this.personpictureRepository = Registry.RepositoryFactory.GetPersonPictureRepository();
            this.personaccountRepository = Registry.RepositoryFactory.GetPersonAccountRepository();
            this.personstatusRepository = Registry.RepositoryFactory.GetPersonStatusRepository();
            this.patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            this.patientrepresentativeRepository = Registry.RepositoryFactory.GetPatientRepresentativeRepository();
        }

        public PatientRepresentativeController(ISexRepository sexRepository, IPersonPictureRepository personpictureRepository, IPersonAccountRepository personaccountRepository, IPersonStatusRepository personstatusRepository, IPatientRepository patientRepository, IPatientRepresentativeRepository patientrepresentativeRepository)
        {
			this.sexRepository = sexRepository;
			this.personpictureRepository = personpictureRepository;
			this.personaccountRepository = personaccountRepository;
			this.personstatusRepository = personstatusRepository;
			this.patientRepository = patientRepository;
			this.patientrepresentativeRepository = patientrepresentativeRepository;
        }

        //
        // GET: /PatientRepresentative/

        public ViewResult Index()
        {
            return View(patientrepresentativeRepository.All);//Including(patientrepresentative => patientrepresentative.Sex, patientrepresentative => patientrepresentative.Picture, patientrepresentative => patientrepresentative.PersonStatus, patientrepresentative => patientrepresentative.Addresses, patientrepresentative => patientrepresentative.Contacts, patientrepresentative => patientrepresentative.CitizenShips, patientrepresentative => patientrepresentative.Informations, patientrepresentative => patientrepresentative.PersonRoles, patientrepresentative => patientrepresentative.Groups, patientrepresentative => patientrepresentative.Documents, patientrepresentative => patientrepresentative.Assignments, patientrepresentative => patientrepresentative.InteractionsWith, patientrepresentative => patientrepresentative.Patient));
        }

        //
        // GET: /PatientRepresentative/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patientrepresentativeRepository.Find(id));
        }

        //
        // GET: /PatientRepresentative/Create

        public ActionResult Create()
        {
			ViewBag.PossibleSexes = sexRepository.All;
			ViewBag.PossiblePictures = personpictureRepository.All;
			ViewBag.PossiblePersonAccounts = personaccountRepository.All;
			ViewBag.PossiblePersonStatus = personstatusRepository.All;
			ViewBag.PossiblePatients = patientRepository.All;
            return View();
        } 

        //
        // POST: /PatientRepresentative/Create

        [HttpPost]
        public ActionResult Create(PatientRepresentative patientrepresentative)
        {
            if (ModelState.IsValid) {
                patientrepresentativeRepository.Create(patientrepresentative);
                patientrepresentativeRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleSexes = sexRepository.All;
				ViewBag.PossiblePictures = personpictureRepository.All;
				ViewBag.PossiblePersonAccounts = personaccountRepository.All;
				ViewBag.PossiblePersonStatus = personstatusRepository.All;
				ViewBag.PossiblePatients = patientRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientRepresentative/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleSexes = sexRepository.All;
			ViewBag.PossiblePictures = personpictureRepository.All;
			ViewBag.PossiblePersonAccounts = personaccountRepository.All;
			ViewBag.PossiblePersonStatus = personstatusRepository.All;
			ViewBag.PossiblePatients = patientRepository.All;
             return View(patientrepresentativeRepository.Find(id));
        }

        //
        // POST: /PatientRepresentative/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientRepresentative patientrepresentative)
        {
            if (ModelState.IsValid) {
                patientrepresentativeRepository.Update(patientrepresentative);
                patientrepresentativeRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleSexes = sexRepository.All;
				ViewBag.PossiblePictures = personpictureRepository.All;
				ViewBag.PossiblePersonAccounts = personaccountRepository.All;
				ViewBag.PossiblePersonStatus = personstatusRepository.All;
				ViewBag.PossiblePatients = patientRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientRepresentative/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patientrepresentativeRepository.Find(id));
        }

        //
        // POST: /PatientRepresentative/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pr = patientrepresentativeRepository.Find(id);
            patientrepresentativeRepository.Delete(pr);
            patientrepresentativeRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

